from wxpyview.ui.component.common.basewidget import *
import wxpyview.ui.component.widgets.sizer.common.library as SizerLibrary

class FlexGridCell(Widget):
    def _setSizerParams(self, meta_widget):
        self.sizer_params = {}
        
        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
        
        align = dom.getAttribute("align")
        valign = dom.getAttribute("valign")
        expand = ComponentLibrary.str2bool(dom.getAttribute("expand"), False)
        
        flag = SizerLibrary.align(align) | SizerLibrary.valign(valign) | SizerLibrary.border(dom.getAttribute("border"))
        
        if expand: flag |= wx.EXPAND
        
        self.sizer_params["proportion"] = ComponentLibrary.str2int(dom.getAttribute("proportion"), 0)
        self.sizer_params["flag"] = flag
        self.sizer_params["border"] = ComponentLibrary.str2int(dom.getAttribute("borderSize"), 0)
        self.sizer_params["userData"] = None
    
    def getSizerParams(self):
        return self.sizer_params

    def create(self, meta_widget):
        self._setSizerParams(meta_widget)
        return self
    
    @classmethod
    def getWidget(self, meta_widget):       
        child_meta_widgets = meta_widget.getChildMetaWidgets()
        
        if len(child_meta_widgets) > 1:
            # TODO: to encompass with container
            pass
        elif len(child_meta_widgets) == 0:
            return None
        else: # only one child
            child_widget = child_meta_widgets[0].getWidget()
            return child_widget